<template>
  <div class="customerVip">
    <!-- 登录管理 -->
    <div class="login">

      <el-form :model="ruleForm" ref="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
        <p class="title">法治云</p>
        <el-form-item label="账号" prop="userName">

          <el-input type="text" v-model.trim="ruleForm.userName" auto-complete="off" placeholder="请输入您的账号" @blur="changBlur"> </el-input>
        </el-form-item>

        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model.trim="ruleForm.password" @keyup.enter.native="submitForm('ruleForm')" @blur="changBlur" auto-complete="off" placeholder="请输入您的密码">
          </el-input>
        </el-form-item>

        <el-form-item v-show='isShow'>
          <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import path from '@/network'
export default {
  data () {
    var checkAccount = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('账号不能为空'));
      } else {
        callback();
      }

    };
    var checkPass = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('密码不能为空'));
      } else {
        callback();
      }
    };

    return {
      logining: false,
      ruleForm: {
        userName: "",
        password: "",
      },
      rules: {
        userName: [
          { validator: checkAccount, trigger: 'blur' }
        ],
        password: [
          { validator: checkPass, trigger: 'blur' }

        ],
      },
      documentHeight: document.body.height,
      showHeight: document.body.height,
      isShow: true
    };
  },

  mounted () {
    window.onresize = () => {
      this.showHeight = document.body.height
    }
  },

  watch: {
    showHeight () {
      if (this.documentHeight > this.showHeight) {
        this.isShow = false
      } else {
        this.isShow = true
      }

    }
  },

  methods: {
    changBlur () {
      setTimeout(() => {
        const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
        window.scrollTo(0, Math.max(scrollHeight, 0))
      }, 100)
    },

    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.login()
          //this.$router.push('/index')
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm (formName) {
      this.$refs[formName].resetFields();
    },

    login () {
      path.login({
        userName: this.ruleForm.userName,
        password: this.ruleForm.password
      }
      ).then(res => {
        if (res.success == 0) {
          localStorage.setItem("islogin", true)
          this.$router.push('/index')
        }
      })
    },
  },

};
</script>

<style>
.customerVip {
  width: 100%;
  height: 100%;
  position: relative;
  background: url("../assets/image/login_img_bg@2x.png") no-repeat;
  background-size: 100% 100%;
}

.customerVip .login {
  position: absolute;
  width: 46%;
  height: 80%;
  left: 50%;
  top: 50%;
  background: url("../assets/image/login_img_bg_1@2x.png") no-repeat;
  background-size: 100% 100%;
  text-align: center;
  margin-left: -23%;
  margin-top: -23%;
}

.login .el-form-item__label {
  width: 100% !important;
  display: block;
  text-align: center !important;
  font-size: 18px;
}

.login .title {
  color: #4d657b;
  font-size: 30px;
  margin: 10%;
}
.login .el-input__inner {
  height: 50px;
  line-height: 50px;
  margin-left: 40px;
  width: 85% !important;
  outline: none;
  border: none;
  background-color: inherit;
  text-align: center;
  margin: 0 auto !important;
}
.login .demo-ruleForm {
  width: 60%;
  margin: 20%;
}
.login .el-input {
  width: 85%;
  margin: 0 auto 30px auto;
  border-bottom: 1px solid #ccc;
  font-size: 18px;
  height: 60px;
  line-height: 60px;
  text-align: center;
}

.login .el-form-item__error {
  top: 85%;
  left: 40%;
}
.login .el-form-item__content {
  margin-left: 0 !important;
}
.login form img {
  width: 30px;
  position: absolute;
  top: 10px;
  left: 10px;
  vertical-align: middle;
}
.login .el-button {
  width: 100%;
  background: linear-gradient(
    0deg,
    rgba(47, 129, 237, 1),
    rgba(46, 233, 216, 1)
  );
  box-shadow: 2px 8px 9px 0px rgba(138, 138, 138, 0.12);
  border-radius: 10px;
  color: #fff;
  height: 60px;
  line-height: 60px;
  padding: 0;
  font-size: 20px;
  font-weight: bold;
  border: none;
}
</style>
  